// pages/users/users.js
const app = getApp();
Page({
  /**
   * 页面的初始数据
   */
  data: {
    list: [1,2,3]
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var that = this;
    wx.request({
      url: app.ipaddress+'getRegisterUser',
      method: 'GET',
      data: {},
      success: function (res) {
        var list = res.data.list;
        if (list == null) {
          var toastText = '获取数据失败' + res.data.errMsg;
          wx.showToast({
            title: toastText,
            icon: '',
            duration: 2000
          });
        } else {
          that.setData({
            list: list
          });
        }
      }
    })
  },
  userAgree (e) {
    var that = this;
    var userId = e.target.dataset.id;
    var {index} = e.currentTarget.dataset;
    var list = that.data.list;
    var dataform = {
      "userId": userId
    };
    wx.request({
      url: app.ipaddress+'registerUserThree',
      method: 'POST',
      data: JSON.stringify(dataform),
      header: {
        'Content-Type': 'application/json'
      },
      success: function (res) {
        var result = res.data.success;
        var toastText = '审核完成';
        if (result) {
          list.splice(index,1)
          that.setData({
            list:list
          });
        } else {
          toastText = '操作失败' + res.data.errMsg;
        }
        console.log(res.data.errMsg)
        wx.showToast({
          title: toastText,
          icon: '',
          duration: 2000
        })
      }
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})